package com.zhangsheng.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * @author 张晟
 * @version 1.0
 * @date 2024/3/1 13:54
 */
@Configuration
public class IpAddrConfig {
    @Bean("remoteAddrKeyResolver")
    public KeyResolver remoteAddrKeyResolver() {
        return exchange -> {
            String ip = exchange.getRequest().getRemoteAddress().getHostName();
            System.out.println(ip);
            return Mono.just(ip);
        };
    }
}
